<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div style="padding: 10px;">
	<p>角色菜单配置  [ 当前角色编号：<span id="roleName"></span> ]</p>
	<div style="margin:10px;">
		<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="config()">提交</a>
		<a href="#" class="easyui-linkbutton" icon="icon-reload" onclick="reload()">刷新</a>
		<!-- 
		<a href="#" class="easyui-linkbutton" icon="icon-reload" onclick="view()">预览</a>
		 -->
		<a href="#" class="easyui-linkbutton" icon="icon-back" onclick="$('#dataGrid').show();$('#opPanel').panel('close');">返回</a>
	</div>

	<ul id="menuTree"></ul>
	
	<script type="text/javascript">
	
		$(document).ready(function(){
			$("#roleName").text(decodeURI(decodeURI("${param.name}")));
			$('#menuTree').tree({
				checkbox: true,
				url: 'menu.action?command=getConfigMenuTree&roleid=${param.id }',
				animate: true,
				onClick: function(node){
					$(node.target).find('span.tree-hit').trigger('click');
				}
			});
		});
		
		function reload(){
			$('#menuTree').tree('reload');
		}
		
		function view(){
			alert("尚未实现");
			/*
			$('div.tree-node').each(function(){
				$('#menuTree').tree('expand', this);
			});
			*/
		}
		
		function getChecked(){
			var nodes = $('#menuTree').tree('getChecked');
			var s = '';
			for(var i=0; i<nodes.length; i++){
				if (s != '') s += ',';
				s += nodes[i].id;
			}
			// alert(s);
			return s;
		}
		
		// 配置
		function config(){
			var actionURL = "role.action";
			var params = {
				command: "config",
				id: '${param.id }',
				mids: getChecked
			};
		
			$.get(actionURL, params, function(result){
    			if("true" == result){
					$.messager.alert("友情提示", "您的操作成功!", "info", function(){
						$('#dataGrid').show();
						$('#tt').datagrid('reload');
						$('#opPanel').panel('close');
					});
				}else{
					$.messager.alert("友情提示", "您的操作失败!", "error");
				}
  			});
		}
		
	</script>
	
</div>
